package subject_set.offer100;

import java.util.ArrayList;
import java.util.List;

/**
 * @author haomin
 * @date 2022/10/17 16:05
 **/
public class Offer34 {
    class Solution {
        List<List<Integer>> res = new ArrayList<>();
        public List<List<Integer>> pathSum(TreeNode root, int target) {
            findPath(root, target, new ArrayList<>());
            return res;
        }
        private void findPath(TreeNode root, int target, List<Integer> ret){
            if(root == null) return;
            target -= root.val; ret.add(root.val);
            if(root.left == null && root.right == null && target == 0)
                res.add(new ArrayList<>(ret));
            findPath(root.left, target, ret);
            findPath(root.right, target, ret);
            ret.remove(ret.size()-1);
        }
    }
}